﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.Adapters;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.ApplicationPages;
using Microsoft.SharePoint.Administration;
using System.Reflection;
using Microsoft.SharePoint;
using System.Diagnostics;
using System.Web.UI;
using System.Web.UI.HtmlControls;

namespace Macaw.Moss2007.TimerJobServerSelectorSolution
{
    public class JobEditControlAdapter : PageAdapter
    {

        protected override void CreateChildControls()
        {
            ServerSelectorControl selc = (ServerSelectorControl)this.Page.LoadControl("/_layouts/Macaw.Moss2007.TimerJobServerSelectorSolution/ServerSelectorControl.ascx");
            selc.EditPage = (JobEditPage)this.Control;

            Control c = null;

            Stack<Control> cs = new Stack<Control>();
            cs.Push(this.Control);
            while (cs.Count > 0)
            {
                Control cc = cs.Pop();
                switch (cc.ID)
                {
                    case "LabelLastRunTime":
                        c = cc;
                        break;
                    //case"BtnEditJob":
                        //cc.Visible = true;
                        //break;
                    /*case"BtnEnableJob":
                        cc.Visible = true;
                        break;
                    case "BtnDisableJob":
                        cc.Visible = true;
                        break;*/
                    case "BtnDeleteJob":
                        cc.Visible = true;
                        break;
                }




                foreach (Control sc in cc.Controls)
                {
                    cs.Push(sc);
                }
            }

            if (c == null) throw new Exception("C is not set");

            c.Parent.Controls.Add(selc);

            base.CreateChildControls();



        }

    }
}
